import config.AnnotionConfig;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.expression.Expression;
import org.springframework.expression.ExpressionParser;
import org.springframework.expression.spel.standard.SpelExpressionParser;
import service.RoleService;

/**
 * Created by zuoxiao
 * on 2019/6/22.
 */
public class Main {
public static void main(String[] args){
    //ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("beans.xml");
    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(AnnotionConfig.class);

    //Student student1 =(Student) ctx.getBean("student");
    //Student student2 =(Student) ctx.getBean("student");

    //String password = ctx.getEnvironment().getProperty("database.password");

    //testSpringEL();

    //AopTestService aopTestService = ctx.getBean(AopTestService.class);
    //aopTestService.printInfo("hello");

//    SqlSessionTemplate sqlSessionTemplate = ctx.getBean(SqlSessionTemplate.class);
//    Role role = new Role();
//    role.setRoleName("spring-mybatis");
//    role.setNote("ok");
//    sqlSessionTemplate.insert("mapper.Rolemapper.insertRole",role);

//    Rolemapper rolemapper = ctx.getBean(Rolemapper.class);
//    Role role = new Role();
//    role.setRoleName("MapperFactoryBean");
//    role.setNote("ok");
//    rolemapper.insertRole(role);

//    RoleListService roleListService =  ctx.getBean(RoleListService.class);
//    List<Role> roleList = new ArrayList<>();
//    for (int i = 0; i < 4; i++) {
//        Role role = new Role();
//        role.setRoleName("role_"+(i+24));
//        role.setNote("note_"+(i+24));
//        roleList.add(role);
//    }
//    int count = roleListService.insertRoleList(roleList);
//    System.out.println("count="+count);

    RoleService roleService = ctx.getBean(RoleService.class);
    int res = roleService.deleteRole(23l);
    System.out.println("delete flag ="+res);
    ctx.close();
}

   public static void testSpringEL(){
       ExpressionParser parser = new SpelExpressionParser();
       Expression expression = parser.parseExpression("'你好世界！'");
       String result = (String) expression.getValue();
       System.out.println(result);

   }
}
